package com.maochd.platform.config;

import com.maochd.platform.util.TemplateUtils;
import lombok.Data;
import one.util.streamex.StreamEx;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Data
@Configuration
@ConfigurationProperties(prefix = "ding-talk")
public class DingTalkConfig {

    private List<Robot> robots;

    @Data
    public static class Robot {
        private String name;
        private String webhookUrl;
        private String secret;
    }

    public Robot getRobotByName(String name) {
        return StreamEx.of(this.robots)
                .findFirst(robot -> robot.getName().equals(name))
                .orElseThrow(() -> new RuntimeException("找不到对应的钉钉机器人配置: " + name));
    }

}